package com.jpa.element.collection.mapping.tutorial;

import com.jpa.element.collection.mapping.tutorial.domain.Address;
import com.jpa.element.collection.mapping.tutorial.domain.Label;
import com.jpa.element.collection.mapping.tutorial.service.LabelService;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class JpaElementCollectionMappingTutorial {

    public static void main(String[] args) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("JpaElementCollectionMappingTutorial");
        EntityManager em = emf.createEntityManager();
        LabelService labelService = new LabelService(em);

        System.out.println("--- Find label ---");
        Label label = labelService.findLabel(1);
        System.out.println(String.format("Found label: %s", label));
        for (Address address : label.getAddresses()) {
            System.out.println(String.format("Label address: %s", address));
        }
    }
}
